/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pfc.core.db;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 *
 * @author xandru
 */
public class DataSourceFactory {

    public static DataSource getDataSourceFromJNDI(String jndiName)
    {
        DataSource ds =null;
        try {
            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            ds = (DataSource) envCtx.lookup(jndiName);
            //log=org.apache.log4j.Logger.getRootLogger();

            //log.info("Arrancado el logger");
            return ds;
        } catch (NamingException ex) {
            System.out.println("Excepcion: " + ex.getClass().getCanonicalName() + " " +ex.getMessage());
            return null;
        }
    }
}
